import requests
from bs4 import BeautifulSoup
import os
import random

#设置目录并创建文件夹
os.makedirs('/Users/yibohuang/Desktop/jquerypc/')
#进入这个目录
os.chdir('/Users/yibohuang/Desktop/jquerypc/')
#设置URL
all_url = 'http://www.jq22.com/demo/navslider201702240014/'

headers = {'User-Agent':"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"}
start_html = requests.get(all_url,  headers=headers).content.decode()
Soup = BeautifulSoup(start_html, "html.parser")
title = Soup.find_all("script")
f = open('main.html','w')
f.write(str(Soup))
f.close()
for js in title:
    link = js.get('src')
    if link:
        if "http://" in link:
            newdown = link
        else:
            newURL = all_url+link
            fff = requests.get(newURL).content.decode()
            f = open(link, 'w')
            f.write(str(fff))
            f.close()



